package com.xinghou.platform.server.api.bussiness.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.xinghou.platform.dao.main.InterestTagsDAO;
import com.xinghou.platform.dao.main.DataConfigDAO;
import com.xinghou.platform.entity.resp.TastInfoResp;
import com.xinghou.platform.model.main.DataConfig;
import com.xinghou.platform.model.main.InterestTags;
import com.xinghou.platform.server.api.bussiness.TastInfoBusinessService;

@Service("tastInfoServices")
public class TastInfoBusinessServiceImpl implements TastInfoBusinessService {
	
	@Resource
	private DataConfigDAO dataConfigDAO;
	
	@Resource
	private InterestTagsDAO interestTagsDAO;
	
	public List<TastInfoResp> getTastInfoList() throws DataAccessException {
		List<TastInfoResp> tastInfoResps = new ArrayList<TastInfoResp>();
		List<DataConfig> dataConfigs =dataConfigDAO.getDataConfigList(1);
		TastInfoResp tastInfoResp = null;
		
		for (DataConfig dataConfig : dataConfigs) {
			tastInfoResp = new TastInfoResp();
			tastInfoResp.setTaste(dataConfig.getName());
			tastInfoResp.setTid(dataConfig.getTagId().toString());
			tastInfoResps.add(tastInfoResp);
		}
		
		return tastInfoResps;
	}
	
	public List<TastInfoResp> getUserTastInfoList(String userid) throws DataAccessException {
		List<TastInfoResp> tastInfoResps = new ArrayList<TastInfoResp>();
		List<InterestTags> InterestTagss =interestTagsDAO.getInterestTagsByUserId(Integer.valueOf(userid));
		TastInfoResp tastInfoResp = null;
		for (InterestTags interestTags : InterestTagss) {
			tastInfoResp = new TastInfoResp();
			tastInfoResp.setTaste(dataConfigDAO.getDataConfigByTag_id(interestTags.getTagId(),1).getName());
			tastInfoResp.setTid(String.valueOf(interestTags.getTagId()));
			tastInfoResps.add(tastInfoResp);
		}
		
		return tastInfoResps;
	}

}
